package leetcode.easy;

/**
 * ClassName: $88_merge
 * Description:
 * date: 2022-01-30 17:07
 *
 * @author liyifan
 */
public class $88_merge {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] res = new int[m + n];
        int i = 0,j = 0,k = 0;
        while (i < m && j < n) {
            if (nums1[i] >= nums2[j]) {
                res[k++] = nums2[j++];
            } else {
                res[k++] = nums1[i++];
            }
        }
        if (i == m) {
            while (j < n) {
                res[k++] = nums2[j++];
            }
        } else if (j == n){
            while (i < m) {
                res[k++] = nums1[i++];
            }
        }

        for (int l = 0;l < m + n;l++) {
            nums1[l] = res[l];
        }
    }
}
